Joshua King scored a hat-trick as Bournemouth boosted their Premier League survival hopes by beating West Ham to secure a first win in 2017.